package com.itheima.set;

import com.itheima.domain.Student;

import java.util.Comparator;
import java.util.TreeSet;

public class Demo04 {
    public static void main(String[] args) {
        TreeSet<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //this-o
                //o1 要插入的元素
                //o2已经在集合中打元素
                return o1.getAge()-o2.getAge();
            }
        });
        set.add(new Student("坤坤3",27));
        set.add(new Student("坤坤2",26));
        set.add(new Student("坤坤2",22));
        System.out.println(set);
    }
}
